package com.example.rongcloud_im_plugin;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.platform.PlatformView;

public class FlutterActivityView implements PlatformView, MethodCallHandler {
	private final TextView myNativeView;
    private final MethodChannel methodChannel;

    FlutterActivityView(Context context, BinaryMessenger messenger, int id) {
        myNativeView = new TextView(context);
        methodChannel = new MethodChannel(messenger, "plugins/rongcloud_im_plugin_" + id);
        methodChannel.setMethodCallHandler(this);

        myNativeView.setText("我是来自Android的原生TextView");
    }

    @Override
    public View getView() {
        Context mContext = RCIMFlutterWrapper.getInstance().getContent();
        return View.inflate(mContext, R.layout.conversation, null);
        // return myNativeView;
    }

    @Override
    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        switch (methodCall.method) {
            case "setText":
                setText(methodCall, result);
                break;
            default:
                result.notImplemented();
        }

    }

    private void setText(MethodCall methodCall, Result result) {
        String text = (String) methodCall.arguments;
        myNativeView.setText(text);
        result.success(null);
    }

    @Override
    public void dispose() {

    }
}
